//
//  QJPreviewOrderVCHeaderView.m
//  QuanJieShopProject
//
//  Created by 刘中义 on 2018/2/19.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "QJPreviewOrderVCHeaderView.h"
#import "QJMineAddressVC.h"
@implementation QJPreviewOrderVCHeaderView
-(void)awakeFromNib{
    [super awakeFromNib];
    self.addressLabel.text = @"请去添加收货地址";
}

- (IBAction)addressBtnClickAction:(UIButton *)sender {

    QJMineAddressVC *VC = [[QJMineAddressVC alloc]init];
    UIViewController *vc = [self currentViewController];
    [vc.navigationController pushViewController:VC animated:YES];
    VC.getOneAddressBlock = ^(MineAddressModel *model) {
        
//         self.addressLabel.text = [NSString stringWithFormat:@"%@ %@ \n%@ %@ %@ %@",model.link_name,model.tel,model.province,model.city,model.region,model.detail_address];
        [[NSNotificationCenter defaultCenter]postNotificationName:@"addressSelectedNotification" object:model];
    };
}
- (void)headerUpdateDataWithDic:(NSDictionary *)dict{
    if (dict) {
        //收货地址
        NSDictionary *addDic = dict[@"address"];
        if ([addDic isKindOfClass:[NSDictionary class]]) {
            NSString *nameStr = [NSString stringWithFormat:@"%@",addDic[@"consignee"]];
            NSString *telStr = [NSString stringWithFormat:@"%@",addDic[@"mobile"]];
            NSString *provinceStr = [NSString stringWithFormat:@"%@",addDic[@"province_show"]];
            NSString *cityStr = [NSString stringWithFormat:@"%@",addDic[@"city_show"]];
            NSString *regionStr = [NSString stringWithFormat:@"%@",addDic[@"region_show"]];
            NSString *detailAddStr = [NSString stringWithFormat:@"%@",addDic[@"address"]];
            self.addressLabel.text = [NSString stringWithFormat:@"%@ %@ \n%@ %@ %@ %@",nameStr,telStr,provinceStr,cityStr,regionStr,detailAddStr];
            [self.addressBtn setTitle:@"" forState:UIControlStateNormal];
        }else{
            self.addressLabel.text = @"请添加收货地址";
        }
        
    }
}
//当前视图
-(UIViewController *)currentViewController{
    UIViewController *vc;
    for (UIView* next = [self superview]; next; next = next.superview) {
        UIResponder* nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[objc_getClass("UIViewController") class]] ) {
            vc=(UIViewController*)nextResponder;
            
            return vc;
        }
    }
    return vc;
}


@end
